import api from './index'
import { axios, qs } from '@/utils/request'

/**
 * 用户登录
 */
export function login(parameter) {
  return axios({
    url: '/auth/oauth/token',
    method: 'post',
    data: qs.stringify({ ...parameter }),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

export function getSmsCaptcha(parameter) {
  return axios({
    url: api.SendSms,
    method: 'post',
    data: parameter
  })
}
/**
 * 获取用户,权限等信息
 */
export function getInfo() {
  return axios({
    url: '/system/user/info',
    method: 'get'
  })
}

export function getCurrentUserNav(token) {
  return axios({
    url: '/user/nav',
    method: 'get'
  })
}

export function logout(accessToken) {
  return axios({
    url: `/auth/login/loginOut?accessToken=${accessToken}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step(parameter) {
  return axios({
    url: api.twoStepCode,
    method: 'post',
    data: parameter
  })
}
